﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectSurvivor
{
    public class CoinUpgradeItem
    {

        public EasyEvent OnChanged=new EasyEvent();

        public bool UpgradeFinish { get;  set; } = false;  

        public string key { get; private set; }

        public string Description { get;private set; }

        public int Price { get;private set; }

        public void Upgrade() {

            mOnUpgrade?.Invoke(this);
            UpgradeFinish = true;
            OnChanged.Trigger();
            CoinUpgradeSystem.OnCoinUpgradeSystemChanged.Trigger(); 
        }


        public bool ConditionCheck()
        {
            if (mCondition != null)
            {
              return !UpgradeFinish && mCondition.Invoke(this);
            }
            return !UpgradeFinish;
        }

        private Action<CoinUpgradeItem> mOnUpgrade;

        private Func<CoinUpgradeItem, bool> mCondition;


        public CoinUpgradeItem WithKey(string key)
        {
            this.key = key;
            return this;
        }

        public CoinUpgradeItem WithPrice(int price)
        {
            this.Price = price;
            return this;
        }

        public CoinUpgradeItem WithDescription(string description) {  this.Description = description; return this; }

        public CoinUpgradeItem OnUpgrade(Action<CoinUpgradeItem> onUpgrade)
        {
            this.mOnUpgrade=onUpgrade;
            return this;
        }

        public CoinUpgradeItem Condition(Func<CoinUpgradeItem,bool> condition)
        {
            mCondition = condition; 
            return this;
        }
    }
}
